package com.wsp.controllermanagement.controller;

import com.wsp.apimanagement.pojo.dto.Result;
import com.wsp.apimanagement.pojo.entity.Source;
import com.wsp.apimanagement.pojo.vo.IndexInfo;
import com.wsp.apimanagement.service.SourceService;
import com.wsp.apimanagement.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * Package: com.wsp.controllermanagement.controller
 * Description： TODO
 *
 * @Author: 巫思平
 * Copyright: Copyright (c) 2020
 * Version: 1
 */
@Api(tags = "资源接口")
@RestController
@RequestMapping("/source")
@Validated
public class SourceController {
    @Autowired
    private SourceService sourceService;

    @Autowired
    private UserService userService;

    @ApiOperation("获取首页信息")
    @GetMapping("/getIndexInfo/{userId}")
    public Result<IndexInfo> getIndexInfo(@PathVariable("userId") @NotNull @Min(1) Long userId){
        return userService.getIndexInfo(userId);
    }

    @ApiOperation("获取模块对应的资源")
    @GetMapping("/getSourceByModuleId/{moduleId}")
    public Result<List<Source>> getSourceByModuleId(@PathVariable("moduleId") @NotNull @Min(1) Long moduleId){
        return sourceService.getModuleSource(moduleId);
    }
}
